/**
 * 73. 矩阵置零
 * https://leetcode.cn/problems/set-matrix-zeroes/description/?envType=study-plan-v2&envId=top-100-liked
 */
class Solution2 {
    int n, m;
    boolean[][] vist;

    public void setZeroes(int[][] matrix) {
        n = matrix.length; m = matrix[0].length;
        vist = new boolean[n][m];
        for(int i = 0; i < n; i++) {
            for(int j = 0; j < m; j++) {
                if(!vist[i][j] && matrix[i][j] == 0) {
                    vist[i][j] = true;
                    change(matrix, i, j);
                }
            }
        }
    }

    public void change(int[][] matrix, int a, int b) {
        //把该行全变为0
        for(int i = 0; i < m; i++) {
            if(matrix[a][i] != 0) vist[a][i] = true;
            matrix[a][i] = 0;

        }
        //把该列全变为0
        for(int i = 0; i < n; i++) {
            if(matrix[i][b] != 0) vist[i][b] = true;
            matrix[i][b] = 0;
        }
    }
}